package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DishMapper {

    Integer countByCategoryId(Long id);

    @AutoFill(OperationType.INSERT)
    void save(Dish dish);

    Page<DishVO> page(DishPageQueryDTO dto);

    @Select("select * from dish where id = #{id}")
    Dish getDishById(Long id);

    @Delete("delete from dish where id = #{id}")
    void deleteDishById(Long id);

    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    @AutoFill(OperationType.INSERT)
    @Update("update dish set status = #{status}, update_time = #{updateTime}, update_user = #{updateUser} where id = #{id}")
    void updateStatus(Dish dish);

    List<Dish> getCategoryByCategoryIdName(Long categoryId, String name);

    @Select("select d.* from dish d left join setmeal_dish s on d.id = s.dish_id where s.dish_id = #{setmealId}")
    List<Dish> getDishBySetmealId(Long setmealId);

    @Select("select d.*,c.name categoryName from dish d left join category c on d.category_id = c.id where category_id = #{categoryId} and d.status = #{status}")
    List<DishVO> getDishByCategoryId(Dish build);

    @Select("select d.* from order_detail o left join dish d on o.dish_id = d.id where order_id = #{orderId}")
    List<Dish> getDishByOrderId(Long orderId);

    @Select("select count(id) from dish where status = #{status}")
    Integer getStatusCount(Integer status);
}















